#include <unistd.h>
#include <cassert>
#include <functional>
#include "./../../source/server.hpp"

/*
向服务器发送少于Content-Length指定长度的正文
1. 发送一次 服务器会一直等待接收到完整的数据 客户端得不到响应
2. 发送多次 服务器可能会成功接收一次，客户端收到一次正常响应，然后服务器接收和解析请求失败
*/

int main()
{
    Socket cli;
    cli.ClinetCreate("127.0.0.1", 8889);
    std::string req;
    req += "GET /Get HTTP/1.1\r\n";
    req += "Connection: keep-alive\r\n";
    req += "Content-Length: 100\r\n";
    req += "\r\n";
    req += "Hello World!";
    while (true)
    {
        assert(cli.Send(req.c_str(), req.size()) != -1);
        assert(cli.Send(req.c_str(), req.size()) != -1);
        assert(cli.Send(req.c_str(), req.size()) != -1);
        char buff[1024] = { 0 };
        ssize_t n = cli.Recv(buff, 1023);
        assert(n != -1);
        buff[n] = 0;
        std::cout << "[" << buff << "]" << std::endl;
        sleep(30);
    }
    while (true) { sleep(1); }
    return 0;
}